package com.smugmugsoftware.airconcalc.advanced;

import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;

public class WindowDoor extends RoomComponent {

	private int type;
	private int shadedArea;
	private int qty;

	public static final int WINDOW_ARCHED = 2101;
	public static final int WINDOW_TRIANGULAR = 2102;
	public static final int WINDOW_HALF_ARCH = 2103;
	public static final int WINDOW_ELLIPSE = 2111;
	public static final int WINDOW_HALF_ELLIPSE = 2112;
	public static final int WINDOW_SQUARE = 2113;
	public static final int WINDOW_AREA = 2114;

	public WindowDoor(long id) {
		super(id);
		this.type = WINDOW_SQUARE;
	}

	public int getQty() {
		return qty;
	}

	public void setQty(int qty) {
		this.qty = qty;
	}

	public WindowDoor(long id, int type) {
		super(id);
		this.type = type;
	}

	public int getType() {
		return type;
	}

	public String getLongWindowTypeString() {
		if (type == WindowDoor.WINDOW_ARCHED) {
			return "Arched Window";
		} else if (type == WindowDoor.WINDOW_ELLIPSE) {
			return "Elliptical";
		} else if (type == WindowDoor.WINDOW_HALF_ARCH) {
			return "Half Cathedral";
		} else if (type == WindowDoor.WINDOW_HALF_ELLIPSE) {
			return "Chord";
		} else if (type == WindowDoor.WINDOW_TRIANGULAR) {
			return "Peak/Triangular";
		} 
		return "";
	}

	public String getWindowTypeString() {
		if (type == WindowDoor.WINDOW_ARCHED) {
			return "Arched";
		} else if (type == WindowDoor.WINDOW_ELLIPSE) {
			return "Ellipse";
		} else if (type == WindowDoor.WINDOW_HALF_ARCH) {
			return "Half Cath";
		} else if (type == WindowDoor.WINDOW_HALF_ELLIPSE) {
			return "Chord";
		} else if (type == WindowDoor.WINDOW_TRIANGULAR) {
			return "Peak";
		} 
		return "";
	}

	public void setShadedArea(int shadeAreaInt) {
		this.shadedArea = shadeAreaInt;
	}

	public int getShadedArea() {
		return this.shadedArea;
	}

	public String getTypeString() {
		String checkString = this.constructionNumber.substring(0, 2);

		if (checkString.startsWith("10") || checkString.startsWith("11")) {
			return "Door";
		} else if (checkString.startsWith("3")) {
			return "Window";
		} else {
			return "";
		}
	}

	public boolean isAWindow() {
		String checkString = this.constructionNumber.substring(0, 2);

		if (checkString.startsWith("10") || checkString.startsWith("11")) {
			return false;
		} else if (checkString.startsWith("3")) {
			return true;
		} else {
			return false;
		}
	}

	public void setDimensions(int length, int width) {
		this.lengthMinorUnit = length;
		this.widthMinorUnit = width;
		this.useArea = false;
	}

	@Override
	public void setDimensions(int[] dims) {
		setDimensions(dims[0], dims[1]);
	}

	@Override
	public double getTotalLength() {
		return lengthMinorUnit;
	}

	@Override
	public double getTotalWidth() {
		return widthMinorUnit;
	}

	public double getLengthInFeet() {
		return lengthMinorUnit / 12;
	}

	public double getWidthInFeet() {
		return widthMinorUnit / 12;
	}

	public double getAreaInFeet() {
		if (useArea) {
			//			return area / 144;
			return area;
		} else {
			return ((lengthMinorUnit * widthMinorUnit) / 144);
		}
	}

	public double getShadedAreaInFeet() {
		//		return (double) ((double) this.shadedArea / 144);
		return shadedArea;
	}

	public void writeToParcel(Parcel dest, int flags) {
		super.writeToParcel(dest, flags);

		dest.writeInt(type);
		dest.writeInt(shadedArea);
		dest.writeInt(qty);
	}

	public static final Parcelable.Creator<WindowDoor> CREATOR = new Parcelable.Creator<WindowDoor>() {
		public WindowDoor createFromParcel(Parcel in) {
			return new WindowDoor(in);
		}

		public WindowDoor[] newArray(int size) {
			return new WindowDoor[size];
		}
	};

	public WindowDoor(Parcel p) {
		super(p);

		type = p.readInt();
		shadedArea = p.readInt();
		qty = p.readInt();
	}
}